package com.banzhi.shop.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.banzhi.shop.utils.ASUtils;
import com.squareup.picasso.Picasso;
import com.banzhi.shop.MyApp;
import com.banzhi.shop.R;
import com.banzhi.shop.entity.OrderDetails.orderGoodsInfo_data;
import com.banzhi.shop.utils.NumberUtils;

import java.util.List;

/**
 * Created by HT on 2017/5/10.
 */

public class OrderDetailsAdapter extends BaseAdapter<orderGoodsInfo_data> {
    private Context context;


    public OrderDetailsAdapter(Context context, List<orderGoodsInfo_data> data) {
        super(context, data);
        this.context = context;

    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final orderGoodsInfo_data data = getData().get(position);
        viewHolder holder = null;
        if (convertView == null) {
            holder = new viewHolder();
            convertView = getInflater().inflate(R.layout.item_order_details, null);
            holder.ivimage = (ImageView) convertView.findViewById(R.id.iv_image);
            holder.tvtitle = (TextView) convertView.findViewById(R.id.tv_title);
            holder.tvguige = (TextView) convertView.findViewById(R.id.tv_num);
            holder.tvdanjia = (TextView) convertView.findViewById(R.id.tv_danjia);

            convertView.setTag(holder);
        }
        holder = (viewHolder) convertView.getTag();
        if (ASUtils.isCanUse(data.getThumb())) {
            Picasso.with(MyApp.context).load(data.getThumb()).placeholder(R.mipmap.zhanweitu2).into(holder.ivimage);
        } else {
            holder.ivimage.setImageResource(R.mipmap.moren);
        }
        holder.tvtitle.setText(data.getTitle());
        holder.tvguige.setText(data.getTotal());
        if (ASUtils.isCanUse(data.getPrice())) {
            holder.tvdanjia.setText(NumberUtils.DecimalFormat(data.getPrice()));
        }

        return convertView;
    }

    class viewHolder {
        ImageView ivimage;
        TextView tvtitle;
        TextView tvguige;
        TextView tvdanjia;

    }
}